package com.wwgsky.testmodule

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import androidx.appcompat.widget.AppCompatButton
import androidx.fragment.app.Fragment

class MainActivity : AppCompatActivity(), View.OnClickListener {

    lateinit var but_loading: AppCompatButton
    lateinit var but_error: AppCompatButton
    lateinit var but_noValue: AppCompatButton
    lateinit var but_noNet: AppCompatButton
    lateinit var testFragment: TestFragment

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        but_loading = findViewById<AppCompatButton>(R.id.but_loading)
        but_error = findViewById<AppCompatButton>(R.id.but_error)
        but_noValue = findViewById<AppCompatButton>(R.id.but_noValue)
        but_noNet = findViewById<AppCompatButton>(R.id.but_noNet)

        but_loading.setOnClickListener(this)
        but_error.setOnClickListener(this)
        but_noValue.setOnClickListener(this)
        but_noNet.setOnClickListener(this)

        testFragment = TestFragment()

        supportFragmentManager
            .beginTransaction()
            .add(
                R.id.frameLayout,
                testFragment
            ).commit()

    }

    override fun onClick(v: View?) {

        when(v){

            but_loading -> {

                testFragment.startLoad("加载中")

            }

            but_error -> {

                testFragment.showLoadError("加载错误")

            }

            but_noValue -> {

                testFragment.showNoValue("无数据了喔")

            }

            but_noNet -> {

                testFragment.showNoNet("无网络了喔")

            }

        }

    }


}